﻿@{
    ViewBag.Title = "新增设备信息";
}
@model FMS.UI.Areas.Factory.ViewModel.Factory_Machines
@section headsecion{
    <style type="text/css">
        body {
            margin: 0;
            align-self: center;
        }

        .tbList {
            border: 1px solid #ddd;
            height: 99.5%;
            border-collapse: collapse;
            margin: 0;
            padding: 0;
            width: 100%;
            border-top-width: 0;
            border-bottom-width: 0;
            border-left-width: 0;
            border-right-width: 0;
        }

        .tbList td, th {
            border: 1px solid #ddd;
            padding: 0 5px;

        }

        .tdName {
            text-align: center;
            width: 60px;
            height: 35px;
        }
        .tdweight {
            width: 220px;
        }

        #form0 {
            margin: 0;
            padding: 0;
        }
         .ui-autocomplete {
            max-height: 110px; /*高度值*/
            overflow-y: auto; /*超过高度出现滚动条*/            
            overflow-x: hidden; /*横向超出隐藏，如果要出现横向滚动，设置为auto即可*/
        }
    </style>
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="~/Scripts/jquery-1.4.4.js"></script>
<script src="~/Scripts/jquery.ui.widget.js"></script>
<script src="~/Scripts/jquery.ui.core.js"></script>
<script src="~/Scripts/jquery.ui.button.js"></script>
<script src="~/Scripts/jquery.ui.position.js"></script>
<script src="~/Scripts/jquery.msgProcess.js"></script>
<script src="~/Scripts/jquery.globalHelper.js"></script>
<script src="~/Scripts/jquery.ui.autocomplete.js"></script>
    <script type="text/javascript">
        $(function () {
            // 去掉所有input的autocomplete, 显示指定的除外
            $('input:not([autocomplete]),textarea:not([autocomplete]),select:not([autocomplete])').attr('autocomplete', 'off');

            $('#tbList select,input').attr("disabled", true);
            $('#kind0').attr("disabled", false);
            //$('#enter').attr("disabled", false);
            $('#kind0').change(kindOnechange);
            $('#kind1').change(kindTwochange);
            $('#kind2').change(kind3change);
            $('#company').change(selectDep);
            $('#kind3').change(getmax);
            $("#gongying").autocomplete({
                // 通过函数自定义处理数据源
                source: function (request, response) {
                    // request对象只有一个term属性，对应用户输入的文本
                    // response是一个函数，在你自行处理并获取数据后，将JSON数据交给该函数处理，以便于autocomplete根据数据显示列表
                    var url = "/Factory/FactoryContact/GongYingShang?term=" + request.term;
                    $.ajax({
                        'url': url,
                        dataType: 'json',
                        success: function (dataObj) {
                            var data = jQuery.makeArray(dataObj);
                            var ssd = $.map(data, function (item) {
                                return {
                                    value: item.value,
                                    label: item.label
                                }
                            });
                            response(ssd);
                        }
                    });
                },
                select: function (event, ui) {
                    // ui对象只有一个item属性，对应数据源中被选中的对象
                    $("#gongying").val(ui.item.label);
                    $("#gys").val(ui.item.value);
                    // 必须阻止默认行为，因为autocomplete默认会把ui.item.value设为输入框的value值
                    event.preventDefault();
                },
                mustMatch:true
            });

        });

        function getmax() {
            var id = this.value;
            var code = $('#factory_bar_code');
            if ($('#kind3  option:selected').text() == '选择分类') {
                code.val("");
                $('#tbList select,input').attr("disabled", true);
                $('#kind0').attr("disabled", false);
                $('#kind1').attr("disabled", false);
                $('#kind2').attr("disabled", false);
                $('#kind3').attr("disabled", false);
                return;
            };
            $.post("/Factory/FactoryMachines/GetMax", { "id": id }, function (data) {
                code.val(data);
               $('#tbList select,input').attr("disabled", false);
                // code.attr("disabled", true);
                code.attr("readOnly", true);
            });
        };

        function kindOnechange() {
            var sel = $("#kind1");
            var $kind2 = $("#kind2");
            var $kind3 = $("#kind3");
            var $code = $("#factory_bar_code");
            sel.empty();
            $kind2.empty();
            $kind3.empty();
            $code.val("");
            $('#tbList select,input').attr("disabled", true);
            $('#kind0').attr("disabled", false);
            if ($('#kind0  option:selected').text() == '选择分类') {
                sel.attr("disabled", true);
                $kind2.attr("disabled", true);
                $kind3.attr("disabled", true);
                $code.attr("disabled", true);
                
                return;
            }
            sel.attr("disabled", false);
            var id = this.value;
            $.post("/Factory/Factory_Machines_Kind/Kind1sel", { "id": id }, function (data) {
                sel.append("<option value='-1'>选择分类</optin>");
                $.each(data, function (name, value) {
                    sel.append("<option value=" + value.id + ">" + value.k1name + "</optin>");
                });
            });


        };
        function kindTwochange() {
            var sel = $("#kind2");
            var $kind3 = $("#kind3");
            var $code = $("#factory_bar_code");
            sel.empty();
            $kind3.empty();
            $code.val("");
            $('#tbList select,input').attr("disabled", true);
            $('#kind0').attr("disabled", false);
            $('#kind1').attr("disabled", false);
            if ($('#kind1  option:selected').text() == '选择分类') {
                sel.attr("disabled", true);
                $kind3.attr("disabled", true);
                $code.attr("disabled", true);
                return;
            }
            sel.attr("disabled", false);
            var id = this.value;
            $.post("/Factory/Factory_Machines_Kind/Kind2sel", { "id": id }, function (data) {
                sel.append("<option value='-1'>选择分类</optin>");
                $.each(data, function (name, value) {
                    sel.append("<option value=" + value.id + ">" + value.k2name + "</optin>");
                });
            });
        };

        function kind3change() {
            var sel = $("#kind3");
            var $code = $("#factory_bar_code");
            sel.empty();
            $code.val("");
            $('#tbList select,input').attr("disabled", true);
            $('#kind0').attr("disabled", false);
            $('#kind1').attr("disabled", false);
            $('#kind2').attr("disabled", false);
            if ($('#kind2  option:selected').text() == '选择分类') {
                sel.attr("disabled", true);
                $code.val("");
                $code.attr("disabled", true);
                return;
            }
            sel.attr("disabled", false);
            var id = this.value;
            $.post("/Factory/Factory_Machines_Kind/Kind3sel", { "id": id }, function (data) {
                sel.append("<option value='-1'>选择分类</optin>");
                $.each(data, function (name, value) {
                    sel.append("<option value=" + value.id + ">" + value.k2name + "</optin>");
                });
            });
        };

        function selectDep() {
            var sel = $("#dep");
            sel.empty();
            if ($('#company  option:selected').text() == '选择公司') {
                sel.attr("disabled", true);
                return;
            }
            sel.attr("disabled", false);
            var id = this.value;
          
           
            $.post("/Admin/Department/SelectDep", { "id": id }, function (data) {
                sel.append("<option value='-1'>选择部门</optin>");
                $.each(data, function (name, value) {
                    sel.append("<option value=" + value.depId + ">" + value.depName + "</optin>");
                });
            });
        };


        function Begin() {
          
        };

        function Complete(xhrobj) {
            $.msgProcess(xhrobj.responseText, function () {
                $.globalHelper.closeCommonWindow();
                $.globalHelper.reloadSeletecTabDataGrid();
            });
        };
    </script>
}
@using (Ajax.BeginForm(new AjaxOptions()
{
    OnBegin = "Begin",
    OnComplete = "Complete"

}))
{
    <table id="tbList" class="tbList">
        <tr>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_Kind_Type_Id)</td>
            <td class="tdweight">@Html.DropDownListFor(o => o.factory_Machines_Kind_Type_Id, ViewBag.Machines_Kind_Type as IEnumerable<SelectListItem>, "选择分类", new { style = "width:135px ", select = "size:10", id = "kind0"})</td>
            <td class="tdName">二级分类</td>
            <td class="tdweight"> <select id=kind1 style="width:135px" name="factory_Machines_Kind1_Id"></select></td>
        </tr>
        <tr>
            <td class="tdName">三级分类</td>
            <td> <select id=kind2 style="width:135px" name="factory_Machines_Kind2_Id"></select></td>
            <td class="tdName">设备类型</td>
            <td> <select id=kind3 style="width:135px" name="factory_Machines_Kind_Id"></select></td>


        </tr>

        <tr>
            <td class="tdName">设备编码</td>
            <td><input type="text" id="factory_bar_code" name="factory_bar_code" /></td>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_Name)</td>
            <td>@Html.TextBoxFor(o => o.factory_Machines_Name)@Html.ValidationMessageFor(o => o.factory_Machines_Name)</td>
            
        </tr>

        <tr>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_Type)</td>
            <td>@Html.TextBoxFor(o => o.factory_Machines_Type)@Html.ValidationMessageFor(o => o.factory_Machines_Type)</td>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_Size)</td>
            <td>@Html.TextBoxFor(o => o.factory_Machines_Size)@Html.ValidationMessageFor(o => o.factory_Machines_Size)</td>
        </tr>


        <tr>
            <td id="tdName">@Html.DisplayNameFor(o => o.factory_supplier_Id)</td>
            <td>
                @Html.TextBoxFor(o => o.factory_Supplier_Id_Name, new { id = "gongying" })@Html.ValidationMessageFor(o => o.factory_Supplier_Id_Name)
                @Html.HiddenFor(o => o.factory_supplier_Id, new { id = "gys" })@Html.ValidationMessageFor(o => o.factory_supplier_Id)
            </td>
            @*<td class="tdName">@Html.DisplayNameFor(o => o.factory_supplier_Id)</td>
            <td>@Html.DropDownListFor(o => o.factory_supplier_Id, ViewBag.Machines_supplier as IEnumerable<SelectListItem>, "", new { style = "width:135px ", select = "size:10" })</td>*@
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_UseDate)</td>
            <td><input id="dd" type="text" class="easyui-datetimebox" required="required" name="factory_Machines_UseDate"></td>

        </tr>

        <tr>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_InDate)</td>
            <td><input id="dd" type="text" class="easyui-datetimebox" required="required" name="factory_Machines_InDate"></td>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_OutDate)</td>
            <td> <input id="dd" type="text" class="easyui-datetimebox" required="required" name="factory_Machines_OutDate"></td>
        </tr>

        <tr>           
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_factory_number)</td>
            <td>@Html.TextBoxFor(o => o.factory_Machines_factory_number)@Html.ValidationMessageFor(o => o.factory_Machines_factory_number)</td>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_KW)</td>
            <td>@Html.TextBoxFor(o => o.factory_Machines_KW)@Html.ValidationMessageFor(o => o.factory_Machines_KW)</td>
        </tr>

        <tr>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_Price)</td>
            <td>@Html.TextBoxFor(o => o.factory_Machines_Price)@Html.ValidationMessageFor(o => o.factory_Machines_Price)</td>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_depreciation)</td>
            <td>@Html.TextBoxFor(o => o.factory_depreciation)@Html.ValidationMessageFor(o => o.factory_depreciation)</td>
        </tr>

        <tr>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_networth)</td>
            <td>@Html.TextBoxFor(o => o.factory_networth)@Html.ValidationMessageFor(o => o.factory_networth)</td>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_installation_site)</td>
            <td>@Html.TextBoxFor(o => o.factory_Machines_installation_site)@Html.ValidationMessageFor(o => o.factory_Machines_installation_site)</td>

           </tr>
        <tr>
            <td class="tdName">@Html.DisplayNameFor(o => o.Factory_Machines_Company_Id)</td>
            <td>@Html.DropDownListFor(o => o.Factory_Machines_Company_Id, ViewBag.Machines_Company as IEnumerable<SelectListItem>, "选择公司", new { style = "width:135px ", id = "company" })</td>

            <td class="tdName">部门名称</td>
            <td><select id="dep" name="factory_Machines_Department_Id" style="width:135px"></select></td>
            
        </tr>

        <tr>
           <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_EquipmentStatus_Id)</td>
            <td>@Html.DropDownListFor(o => o.factory_Machines_EquipmentStatus_Id, ViewBag.Machines_EquipmentStatus as IEnumerable<SelectListItem>, "", new { style = "width:135px ", select = "size:10" })</td>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_Type_Id)</td>
            <td>@Html.DropDownListFor(o => o.factory_Machines_Type_Id, ViewBag.Machines_Type as IEnumerable<SelectListItem>, "", new { style = "width:135px ", select = "size:10" })</td>
          </tr>

        <tr>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_UseState_Id)</td>
            <td>@Html.DropDownListFor(o => o.factory_Machines_UseState_Id, ViewBag.Machines_UseState as IEnumerable<SelectListItem>, "", new { style = "width:135px ", select = "size:10" })</td>
            <td class="tdName">@Html.DisplayNameFor(o => o.factory_Machines_UserId)</td>
            <td>@Html.TextBoxFor(o => o.factory_Machines_UserId)@Html.ValidationMessageFor(o => o.factory_Machines_UserId)</td>
        </tr>
        

        <tr>
            <td colspan="4" style="text-align: center; border: 0 solid white; padding-top:7px"><input id="enter" type="submit" value="确定" style="height: 27px; width: 68px;  cursor: pointer" /></td>
        </tr>
    </table>
}
